#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
#include <sched.h>
#include <stdio.h>

/*wwj*/
int sched_set(uint32_t q, uint32_t t)
{
  struct sched_param sp;
  int res;

  sp.sched_priority = 0;
  sp.sched_ss_init_budget.tv_nsec = q * 1000;
  sp.sched_ss_init_budget.tv_sec = 0;
  sp.sched_ss_repl_period.tv_nsec = t * 1000;
  sp.sched_ss_repl_period.tv_sec = 0;
  
  printf("Pid: %d\n", getpid());
  fprintf(stderr, "Setting scheduler (%u %u)\n", q, t);
  res = sched_setscheduler(getpid(), SCHED_CBS, &sp);
  if (res < 0) {
    perror("Error in setscheduler!");
    return -1;
  }
  fprintf(stderr, "SetSched done! res=%d\n",res);

  return res;
}
